<template>
<div>
    <div class="search">
        <img class="icon" src="https://youyang-cdn.mdshuzhi.com/upload/icon_search.png" />
        <input type="search" class="search-text" placeholder-class="placeholder" placeholder="搜索关键词找栏目" v-model="search" @keyup.13="searchSubmit" @confirm="searchSubmit" />
    </div>
    <div class="searchlists" v-if="singnav.length>0">
        <scroller ref="myscroller" class="scroll" :on-infinite="infinite">
            <div class="musicItem-box">
            <div class="musicItem" v-for="(item,index) in singnav" :key="index">
                <router-link :to="'/ExclusiveColumnList?id='+item.id">
                    <div class="musicImg">
                        <!-- 新 -->
                        <div class="newText" v-if="index<2">新</div>
                        <img :src="item.imgUrl" />
                        <!-- 听 -->
                        <div class="listenBox">
                            <div>{{item.playCount || 0}}播放</div>
                        </div>
                    </div>
                    <div class="musicWord">{{item.title || '好先生与皓先生'}}</div>
                    <div class="lowSongs">{{item.desc}}</div>
                </router-link>
                <!-- <router-link v-if="item.tag" tag="div" class="lowSongs" :to="'/PopSlowSongs?id='+item.id">{{item.tag}}</router-link> -->
            </div>
            </div>
        </scroller>
    </div>
    <div v-else class="empty">暂无搜索结果~</div>
</div>
</template>
<script>
import controller from "@/components/controllers/controllers";
export default {
    name: "columnSearchList",
    components: {},
    data() {
        return {
            singnav: [],
            page: 1,
            pageSize: 10,
            isEnd: false,
            search: ""
        };
    },
    mounted() {
      window.addEventListener('mousewheel',this.handleScroll);
      this.search = this.$route.query.search || "";
      this.categoryListover()
    },
    destroyed(){
      window.removeEventListener('mousewheel',this.handleScroll)
    },
    methods: {
        handleScroll(e){
            let that = this  //此this指向的是vue
            console.log('此时是',e.wheelDelta)
            if (e.wheelDelta < 0) {
                that.$refs.myscroller && (that.$refs.myscroller.scrollBy(0, 50, true));
            } else {
              that.$refs.myscroller && (that.$refs.myscroller.scrollBy(0, -50, true));
            }
        },
        searchSubmit(){
            this.singnav = []
            this.page = 1
            this.categoryListover()
        },
        categoryListover() {
            let _self = this
            controller.categoryList({
                keyword: this.search,
                page: this.page,
                pageSize: this.pageSize,
            }).then(res => {
                if (res.baseData.list.length > 0) {
                    _self.singnav = _self.singnav.concat(res.baseData.list)
                    _self.isEnd = res.baseData.lastPage
                }
            }).catch(res => {

            })
        },
        // 上拉加载
        infinite(done) {
          setTimeout(() => {
            if (this.isEnd) {
              this.$refs.myscroller.finishInfinite(true); //这个方法是不让它加载了，显示“没有更多数据”，要不然会一直转圈圈
            } else {
              console.log("进行下一次加载操作");
              this.page += 1
              this.categoryListover()
              done(); //进行下一次加载操作
            }
          }, 1500);
        },
    }
};
</script>

<style lang="scss" scoped>
.noDatas {
    width: 100%;
    height: 100%;
}

.search {
    padding: 24px;
    position: relative;

    .icon {
        width: 28px;
        height: 28px;
        position: absolute;
        z-index: 1;
        top: 0;
        bottom: 0;
        left: 48px;
        margin: auto;
    }

    .search-text {
        padding: 0 24px 0 77px;
        width: 100%;
        height: 64px;
        background: rgba(246, 246, 250, 1);
        border-radius: 32px;
        font-size: 28px;
        border: none;
    }
}

.searchlists {
    padding: 0 30px;
		margin-top: 32px;
		box-sizing: border-box;
		width: 100%;
    .scroll {
      position: static;
      /deep/ &._v-container{
        height: auto !important;
        ._v-content{
          padding-bottom: 40px;
        }
      }
      .musicItem-box{
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
      }

      /* 音乐 */
      .musicItem {
          width: 48%;
          position: relative;
          margin-bottom: 26px;
          background-color: #F2F2F2;
          border-radius: 8px;

          .musicImg {
              width: 100%;
              // height: 330px;
              border-radius: 8px;
              overflow: hidden;
              position: relative;

              img {
                  width: 100%;
                  height: 100%;
                  background: #333;
              }

              .newText {
                  position: absolute;
                  top: 0;
                  left: 0;
                  width: 71px;
                  height: 71px;
                  color: #fff;
                  font-size: 28px;
                  padding-left: 15px;
                  padding-top: 15px;
                  box-sizing: border-box;
                  background-color: #e66d4d;
                  border-radius: 0 0 85% 0;
              }

              .listenBox {
                  width: 100%;
                  height: 48px;
                  position: absolute;
                  bottom: 16px;
                  left: 0;
                  padding: 0 16px;
                  box-sizing: border-box;
                  display: flex;
                  justify-content: space-between;
                  align-items: center;
                  font-size: 20px;
                  color: #fff;

                  .listenPic {
                      width: 48px;
                      height: 48px;
                      border-radius: 50%;
                      font-size: 25px;
                      display: flex;
                      justify-content: center;
                      align-items: center;
                      background-color: #fff;
                      color: rgb(99, 139, 101);
                  }
              }
          }

          .musicWord {
              width: 100%;
              padding-left: 10px;
              margin-top: 10px;
              box-sizing: border-box;
              font-size: 32px;
              font-weight: 500;
              color: #323232;
          }

          .lowSongs {
              width: 100%;
              max-height: 80px;
              line-height: 40px;
              border-radius: 4px;
              padding-left: 10px;
              box-sizing: border-box;
              margin: 10rpx 0;
              font-size: 26px;
              font-weight: 500;
              color: #A8ACBB;
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 2;
              /* ! autoprefixer: off */
                -webkit-box-orient: vertical;
              /* autoprefixer: on */
          }
      }

      .musicItem:nth-child(2n-1) {
            // margin-right: 26px;
            margin-right: 4%;
        }
    }
}

.empty,
.end {
    font-size: 26px;
    text-align: center;
    color: #a8acbb;
    padding: 20px 0 48px;
}

.recommendlists {
    .title {
        line-height: 35px;
        padding: 0 32px;

        .n {
            color: #323232;
            font-size: 32px;
            font-weight: 700;
        }

        .refesh {
            color: #a8acbb;
            float: right;
        }
    }

    .lists {
        margin-top: 270px;
        height: calc(100vh - 205px) !important;
    }

    .item {
        padding: 36px 32px;
        overflow: hidden;
        position: relative;

        &:after {
            content: "";
            display: inline-block;
            position: absolute;
            z-index: 1;
            bottom: 0;
            left: 32px;
            right: 0;
            margin: auto;
            height: 0;
            border-bottom: #f2f2f2 1px solid;
        }
    }

    .hover {
        background-color: #f6f6fa;
    }

    .pic {
        width: 120px;
        height: 120px;
        border-radius: 8px;
        overflow: hidden;
        margin-right: 20px;
        float: left;
        background-color: #eee;
        position: relative;
    }

    .hot_icon {
        width: 40px;
        height: 40px;
        display: inline-block;
        vertical-align: middle;
        position: absolute;
        z-index: 1;
        top: 0;
        left: 0;
        margin-right: 10px;
    }

    .right {
        overflow: hidden;
    }

    .nums {
        color: #a8acbb;
        margin-bottom: 5px;
        font-size: 24px;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }

    .name {
        color: #323232;
        font-size: 30px;
        margin-bottom: 5px;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }

    .d {
        color: #a8acbb;
        font-size: 26px;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;

        &:before {
            content: "简";
            width: 24px;
            height: 24px;
            margin-top: 6px;
            background: rgba(168, 172, 187, 1);
            border-radius: 4px;
            text-align: center;
            font-size: 20px;
            color: #fff;
            line-height: 24px;
            margin-right: 10px;
            float: left;
        }
    }

    .play {
        width: 88px;
        height: 88px;
        position: absolute;
        top: 0;
        bottom: 0;
        right: 22px;
        margin: auto;
        z-index: 1;
    }
}

img {
    max-width: 100%;
    max-height: 100%;
}
</style>
